﻿using System;
using System.Collections.Generic;

namespace Ndns.Net
{
    internal static class TransactionIdGenerator
    {

        public static IEnumerable<ushort> GetSequentialTransactionId()
        {
            int i = 0;

            while (true)
            {
                i++;
                if (i > ushort.MaxValue)
                    i = 1;

                yield return (ushort)i;
            }
        }

        public static IEnumerable<ushort> GetRandomTransactionId()
        {
            var rand = new Random();
            var b = new byte[2];
            while (true)
            {
                rand.NextBytes(b);
                yield return BitConverter.ToUInt16(b, 0);
            }
        }
    }
}
